import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/login")
public class ServletDemo extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        // 获取用户名参数
        String username = req.getParameter("username");

        // 设置响应内容类型和字符编码
        resp.setContentType("text/html;charset=utf-8");

        // 写入响应
        PrintWriter writer = resp.getWriter();

        if (username == null) {
            writer.write("用户名不能为空");
        } else if ("zhangsan".equals(username)) {
            writer.write("张三，欢迎你！");
        } else if ("lisi".equals(username)) {
            writer.write("李四，欢迎你！");
        } else {
            writer.write("你没有使用权限");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("test");

    }

}